import Mock from 'mockjs';
const data1 = Mock.mock({
  "string|4": "yx！"
})
const data2 = Mock.mock({
  "string|1-8": "yx"
})
const data3 = Mock.mock({
  string: "@cword(1)",
  str: '@cword(10,15)'
})
const data4 = Mock.mock({
  title: "@ctitle",
  sentence: '@csentence'
})
const data5 = Mock.mock({
  title: "@ctitle(8)",
  sentence: '@csentence(50)'
})

const data6 = Mock.mock({
  title: "@ctitle(5,8)",
  sentence: '@csentence(50,100)'
})
const data7 = Mock.mock({
  content: '@cparagraph()' 
})
const data8 = Mock.mock({
  "number|1-999": 1
})
const data9 = Mock.mock({
  name: '@cname()',
  idCard: '@id()',
  address: '@city(true)' // 如果@city(),只会生成市，如果@city(true)会生成省和市
})

const data11 = Mock.mock({
  image: "@image('300x300', '#50B347', '#FFF', 'Mock.js')"
})
const time = Mock.mock({
  time1: '@date()', // 只有年月日
  time2: '@date(yyyy-MM-dd hh:mm:ss)'
})
const data12 = Mock.mock({
  'list|50-99':[
      {
          name: '@cname()',
          address: '@city(true)',
          id: '@increment(1)' // 每次都增加1
      }
  ]
})
const data13 = Mock.mock({
  "list|8": [
    {
      "id": '@increment(1)',
      "title": "@ctitle",
      "image": "@image('300x300', '#50B347', '#FFF', 'vant')",
      "content": "@cparagraph",
      "add_time": "@date(yyyy-MM-dd hh:mm:ss)"
    }
  ]
})

Mock.mock('/api/delete/news', 'post', (options) => {
  let body = JSON.parse(options.body)
  const index = data13.list.findIndex(item => item.id === body.id)
  data13.list.splice(index, 1)
  return {
    status: 200,
    message: '删除成功',
    list: data13.list
  }
})
Mock.mock('/api/add/news', 'post', (options) => {
  let body = JSON.parse(options.body)
  
  data13.list.push(Mock.mock({
    "id": '@increment(1)',
    "title": body.title,
    "content": body.content,
    "add_time": "@date(yyyy-MM-dd hh:mm:ss)"
  }))

  return {
    status: 200,
    message: '添加成功',
    list: data13.list
  }
})
Mock.mock('/api/get/user','get',()=>{
  const data131 = Mock.mock({
    "list|8": [
      {
        "id": '@increment(1)',
        "title": "@ctitle",
        "image": "@image('300x300', '#50B347', '#FFF', 'vant')",
        "content": "@cparagraph",
        "add_time": "@date(yyyy-MM-dd hh:mm:ss)"
      }
    ]
  })
  return {
      status: 200,
      message: '获取新闻列表数据成功',
      data: data131,
      code:0
  }
})

// Mock.mock('/api/post/user','post',()=>{
//   return {
//       status: 200,
//       message: '添加新闻列表数据成功'
//   }
// })​